﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Models;

namespace DAL
{
    public static partial class View_PointService
    {
        public static IList<View_Point> GetAllView_Points()
        {
            string sqlAll = "SELECT top 10 * FROM View_Point order by Po desc";
            return GetView_PointsBySql(sqlAll);
        }

        private static IList<View_Point> GetView_PointsBySql(string safeSql)
        {
            List<View_Point> list = new List<View_Point>();

            using (SqlDataReader dr = DBHelper.ExecuteGetReader(CommandType.Text, safeSql, null))
            {
                while (dr.Read())
                {
                    View_Point videoPoint = new View_Point();

                    videoPoint.ID = (int)dr["ID"];
                    videoPoint.Title = (string)dr["Title"];
                    videoPoint.Po = Convert.ToSingle(dr["Po"]);

                    list.Add(videoPoint);
                }
            }
            return list;
        }

        private static IList<View_Point> GetView_PointsBySql(string safeSql, params SqlParameter[] para)
        {
            List<View_Point> list = new List<View_Point>();

            using (SqlDataReader dr = DBHelper.ExecuteGetReader(CommandType.Text, safeSql, para))
            {
                while (dr.Read())
                {
                    View_Point videoPoint = new View_Point();
                    videoPoint.ID = (int)dr["ID"];
                    videoPoint.Title = (string)dr["Title"];
                    videoPoint.Po = Convert.ToSingle(dr["Po"]);
                    list.Add(videoPoint);
                }
            }
            return list;
        }
    }
}
